﻿#环境:freebsd8.3 i386
#安装包在:email0dot0@163.com@http://yunpan.360.cn\待上传
 
# op as user root
#uuid-1.6.2.tar.gz
make clean && ./configure --prefix=/usr/local/uuid-1.6.2 && make && make install

# 安装 termcap-1.3.1.tar.gz 和 readline  (realine need termcap)
cd termcap-1.3.1 && ./configure && make && make install
#termcap必须安装在默认位置，不要使用--prefix=/usr/local/termcapXXX，否则 readline 找不到他


cd  readline-6.3 && ./configure  --prefix=/usr/local/readline-6.3 && make && make install
#/sbin/lvm依赖/lib/libreadline.so.xxx，如果把readline安装到默认位置，导致lvm有可能去使用新安装的libreadline，这就有可能导致lvm无法运行，而系统的磁盘分区使用了lvm，
# 所以可能导致系统启动失败
#所以不要把readline安装到默认位置，不要让lvm使用这个新的libreadline

#第一次出现了无法获取/usr/local/readline-6/lib/libhistory.a，再次运行却又没有这个错误了
 #如果不安装 termcap，只安装了readline，则configure postgresql9.3.5时，依然说找不到readline

# termcap 应该和curses是同一种东西

#参照360yunpan email0dot0@163 root/install/python/install.sh安装python2.7.6
export PATH=/usr/local/Python-2.7.6/bin/:$PATH
./configure --prefix=/usr/local/postgresql-9.3.5 --with-ossp-uuid --with-readline --with-libraries="/usr/local/uuid-1.6.2/lib/ /usr/local/readline-6.3/lib" --with-includes="/usr/local/uuid-1.6.2/include/ /usr/local/readline-6.3/include" --with-python
make && make install
cd ./contrib/uuid-ossp/  && make && make install
 
adduser postgres
ln -s /usr/local/postgresql-9.3.5 /usr/local/postgresql
mkdir /usr/local/postgresql/data/
chown postgres /usr/local/postgresql/data
 
su - postgres
#op as user postgres
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data
#or:
su postgres -c "/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data"
#start db server
/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data/ > /usr/local/postgresql/data/postgresql.log 2>&1 &
#or:
su postgres -c"/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data/ > /usr/local/postgresql/data/postgresql.log 2>&1 &"
 
#create db
/usr/local/postgresql/bin/createdb test
 
#connect to db
/usr/local/postgresql/bin/psql test
 
#shutdown
/usr/local/postgresql/bin/pg_ctl stop -D /usr/local/postgresql/data/
#or:
/usr/local/postgresql/bin/pg_ctl stop -D /usr/local/postgresql/data/ -m fast
 
 
#modify allow client
/usr/local/postgresql/data/postgresql.conf : listen_addresses = '*'
/usr/local/postgresql/data/pg_hba.conf    :     "host    all             all             192.168.0.0/16            trust"
 
##############################################
#install postgis
#postgis-2.1.4.tar.gz   proj-4.8.0.tar.gz     geos-3.4.2.tar.bz2   json-c-0.10.tar.gz   gdal-1.9.2.tar.gz
cd /root/geos-3.4.2
./configure --prefix=/usr/local/geos-3.4.2 && make && make install
echo "/usr/local/geos-3.4.2/lib/" > /etc/ld.so.conf.d/geos.conf
ldconfig && ldconfig -p | grep geos
 
cd /root/proj-4.8.0
./configure --prefix=/usr/local/proj-4.8.0 && make && make install
echo "/usr/local/proj-4.8.0/lib/" > /etc/ld.so.conf.d/proj4.conf
ldconfig && ldconfig -p | grep proj
 
cd /root/json-c-0.10
./configure --prefix=/usr/local/json-c-0.10 && make && make install
#may a bug of makefile:
cd /root/json-c-0.10 && cp config.h json_object_iterator.h /usr/local/json-c-0.10/include/json/
echo "/usr/local/json-c-0.10/lib/" > /etc/ld.so.conf.d/json-c.conf
ldconfig && ldconfig -p | grep json
 
cd /root/gdal-1.9.2
#./configure --prefix=/usr/local/gdal-1.9.2 && make && make install
#关于jpeg方面报错 先装nginx再装postgresql的 应该是利用了nginx所依赖的jpeg库的
#改成使用gdal自带的jpeg:
make clean && ./configure --prefix=/usr/local/gdal-1.9.2 --with-jpeg=internal && make && make install
echo "/usr/local/gdal-1.9.2/lib/" > /etc/ld.so.conf.d/gdal.conf
ldconfig && ldconfig -p | grep gdal
 
cd /root/postgis-2.1.4
./configure \
--prefix=/usr/local/postgis-2.1.4 \
--with-pgconfig=/usr/local/postgresql/bin/pg_config \
--with-jsondir=/usr/local/json-c-0.10/   \
--with-geosconfig=/usr/local/geos-3.4.2/bin/geos-config \
--with-projdir=/usr/local/proj-4.8.0/  \
--with-gdalconfig=/usr/local/gdal-1.9.2/bin/gdal-config \
&& make && make install

#  不知道什么原因，上面的configure命令写在多行时，总是说 directory /usr/local/proj-4.8.0/ not found，猜测可能是某特殊字符或续行符号所导致的
# 或win8.1输入法为中文时复制粘贴后字符被更改，将多行命令改为单行：
./configure --prefix=/usr/local/postgis-2.1.4 --with-pgconfig=/usr/local/postgresql/bin/pg_config --with-jsondir=/usr/local/json-c-0.10 --with-geosconfig=/usr/local/geos-3.4.2/bin/geos-config --with-projdir=/usr/local/proj-4.8.0 --with-gdalconfig=/usr/local/gdal-1.9.2/bin/gdal-config && make && make install
# 即可正常执行

#test postgis, op as user postgres
psql -d postgres -c "select * from pg_available_extensions;"
psql -d test -c "create extension postgis;"